'use strict';

const RouterService = require('../base');

class PurchaserService extends RouterService {
  static get modelName() {
    return 'Business.Purchaser';
  }

  // 供应商登录
  async login(payload) {
    const { username, password } = payload;

    if (!username || !password) {
      return null;
    }

    // 查找供应商
    const supplier = await this.model.findOne({
      where: {
        username,
        password, // 明文比较
        deleted: 0
      }
    });
    if (supplier.status === 0) {
      throw new Error('账号已被禁用,请联系管理员');
    }
    return supplier;
  }
}

module.exports = PurchaserService;
